<?php
// Controller/Default.php

class Controller_word extends FLEA_Controller_Action
{
    function actionindex(){
        // $smarty =& $this->_getView();
        // $smarty->display('index.html');
    }
    function actionsetcategory(){
        $categories = FLEA::loadFile('Config_WordCategory.php');
        if($this->_isPOST()){
            $category = $_POST['category'];
            foreach($categories as $key => $value){
                foreach($value as $k => $v){
                    if($v == $category){
                         $_SESSION['word_category'] = $key.$k;
                    }
                }
            }
            $_SESSION['word_db'] = $category;
        }
        $smarty =& $this->_getView(); 
        $current = isset($_SESSION['word_category'])?$_SESSION['word_category']:'全部';
        $smarty->assign('data_select_category', $categories);
        $smarty->assign('selected_category', $current);
        $smarty->display('set_word_category.html');
    }
    function actionclass(){
        $smarty =& $this->_getView();
        $name = empty($_GET['name'])?'grade1words':$_GET['name'];
        $page= (int)$_GET['page'];
        if(empty($page)){
            $page = 1; 
        }
        $table_sentences =& FLEA::getSingleton('Table_'.$name);
        FLEA::loadHelper('Pager');
        $pager =& new FLEA_Helper_Pager($table_sentences,$page,20,null,null,1);
        $data = $pager->findAll();
        $data_page = $pager->getPagerData();
        unset($data_page['pagesNumber']);
        $smarty->assign('data', $data);
        $smarty->assign('name', $name);
        $smarty->assign('data_page', $data_page);
        $smarty->display('classlist.html');
    }
    function actionclassfront(){
        $smarty =& $this->_getView();
        $name = empty($_GET['name'])?'grade1words':$_GET['name'];
        $page= (int)$_GET['page'];
        if(empty($page)){
            $page = 1; 
        }
        $table_sentences =& FLEA::getSingleton('Table_'.$name);
        FLEA::loadHelper('Pager');
        $pager =& new FLEA_Helper_Pager($table_sentences,$page,20,null,null,1);
        $data = $pager->findAll();
        $data_page = $pager->getPagerData();
        unset($data_page['pagesNumber']);
        $smarty->assign('data', $data);
        $smarty->assign('name', $name);
        $smarty->assign('data_page', $data_page);
        $smarty->display('classlist.html');
    }
    function actionclassforuser(){
        if($this->_isPOST()){
            dump($_POST);
        }
        else{
            $smarty =& $this->_getView(); 
            $smarty->assign('selected_category', $current);
            $smarty->display('wordclass.html');
        }
    }
    function actionvoice(){
        $table_voice = & FLEA::getSingleton('Table_tofoonlywordvoice');
        $voice = $table_voice->find(array('Word'=>$_GET['word']));
        Header("Content-type:audio/mp3"); 
        print $voice[VoiceData];
    }
}
